package ee.ut.veebirakendus.model;

import java.util.HashMap;
import java.util.Map;

import ee.ut.veebirakendus.engine.GameEngine.Street;

/**
 * @author Kaarel Hanson
 * 
 */
public class Player {

	private int seatIndex;
	private String name;
	private Card first;
	private Card second;
	private int stack;
	private int totalBets;
	private int bet;
	private boolean player;
	private Hand hand = new Hand();
	private Map<Street, Integer> bets = new HashMap<Street, Integer>();

	public Player(int seatIndex, String name, boolean player) {
		this.seatIndex = seatIndex;
		this.name = name;
		this.stack = 100;
		this.player = player;
	}

	public Player(int seatIndex) {
		this(seatIndex, "Player" + seatIndex, false);
	}

	public void clearBets() {
		bets.clear();
		bets.put(Street.PREFLOP, 0);
		bets.put(Street.FLOP, 0);
		bets.put(Street.TURN, 0);
		bets.put(Street.RIVER, 0);
		totalBets = 0;
		resetLastBet();
	}

	public int getStreetBet(Street street) {
		return bets.get(street);
	}

	public void updateBets(Street street, int bet) {
		int streetBet = getStreetBet(street) + bet;
		bets.put(street, streetBet);
		incrementTotalBets(bet);
	}

	public void setSeatIndex(int seatIndex) {
		this.seatIndex = seatIndex;
	}

	public int getSeatIndex() {
		return seatIndex;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setFirst(Card first) {
		this.first = first;
	}

	public Card getFirst() {
		return first;
	}

	public void setSecond(Card second) {
		this.second = second;
	}

	public Card getSecond() {
		return second;
	}

	public void setStack(int stack) {
		this.stack = stack;
	}

	public int getStack() {
		return stack;
	}

	public int getBets() {
		return totalBets;
	}

	public void incrementTotalBets(int value) {
		totalBets += value;
		stack -= value;
		bet = value;
	}

	public void updateStack(int winnings) {
		stack += winnings;
	}

	public void resetLastBet() {
		bet = 0;
	}

	public int getStreetBet() {
		return bet;
	}

	@Override
	public String toString() {
		return "[Name: " + getName() + ", index: " + getSeatIndex()
				+ ", firstCard: " + getFirst() + ", secondCard: " + getSecond()
				+ ", lastBet: " + getStreetBet() + ", totalbets: " + getBets()
				+ ", stack: " + getStack() + ", isplayer: " + isPlayer() + "]";
	}

	public void setPlayer(boolean player) {
		this.player = player;
	}

	public boolean isPlayer() {
		return player;
	}

	public void setHand(Hand hand) {
		this.hand = hand;
	}

	public Hand getHand() {
		return hand;
	}
}
